/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/



function newTimer(time){
  return function(text){
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(text)
      }, time);
    })
  }
}

const timer10 = newTimer(10);

let string;
timer10('hello').then(res => {
  string = res;
  return timer10('lagou');
}).then(res => {
  string += res;
  return timer10('I ♥ U');
}).then(res => {
  string += res;
  console.log(string)
})

// 执行结果 hellolagouI ♥ U
